﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AddDeleteItemControl.xaml.cs" >
//   J. Prinz
// </copyright>
// <summary>
//   Interaktionslogik für AddDeleteItemControl.xaml
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace AutomationMLMapper.Controls
{
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Controls.Primitives;
    using System.Windows.Data;
    using System.Windows.Input;

    using Microsoft.Windows.Controls.Ribbon;

    /// <summary>
    ///   Interaktionslogik für AddDeleteItemControl.xaml
    /// </summary>
    public partial class AddDeleteItemControl
    {
        #region Static Fields

        /// <summary>
        ///   Dependency Property for the AllowAdd
        /// </summary>
        public static readonly DependencyProperty AllowAddProperty = DependencyProperty.Register(
            "AllowAdd", typeof(bool), typeof(AddDeleteItemControl), new PropertyMetadata(true));

        /// <summary>
        ///   Dependency Property for the AllowDelete
        /// </summary>
        public static readonly DependencyProperty AllowDeleteProperty = DependencyProperty.Register(
            "AllowDelete", typeof(bool), typeof(AddDeleteItemControl), new PropertyMetadata(true));

        /// <summary>
        ///   Dependency Property for the ButtonAddCommand
        /// </summary>
        public static readonly DependencyProperty ButtonAddCommandProperty =
            DependencyProperty.Register(
                "ButtonAddCommand", 
                typeof(ICommand), 
                typeof(AddDeleteItemControl), 
                new PropertyMetadata(default(ICommand)));

        /// <summary>
        ///   Dependency Property for the ButtonAddToolTipDescription
        /// </summary>
        public static readonly DependencyProperty ButtonAddToolTipDescriptionProperty =
            DependencyProperty.Register(
                "ButtonAddToolTipDescription", typeof(string), typeof(AddDeleteItemControl), new PropertyMetadata("add"));

        /// <summary>
        ///   Dependency Property for the ButtonAddToolTip
        /// </summary>
        public static readonly DependencyProperty ButtonAddToolTipProperty =
            DependencyProperty.Register(
                "ButtonAddToolTip", typeof(string), typeof(AddDeleteItemControl), new PropertyMetadata("add"));

        /// <summary>
        ///   Dependency Property for the ButtonDeleteCommand
        /// </summary>
        public static readonly DependencyProperty ButtonDeleteCommandProperty =
            DependencyProperty.Register(
                "ButtonDeleteCommand", 
                typeof(ICommand), 
                typeof(AddDeleteItemControl), 
                new PropertyMetadata(default(ICommand)));

        /// <summary>
        ///   Dependency Property for the ButtonDeleteToolTipDescription
        /// </summary>
        public static readonly DependencyProperty ButtonDeleteToolTipDescriptionProperty =
            DependencyProperty.Register(
                "ButtonDeleteToolTipDescription", 
                typeof(string), 
                typeof(AddDeleteItemControl), 
                new PropertyMetadata("delete"));

        /// <summary>
        ///   Dependency Property for the ButtonDeleteToolTip
        /// </summary>
        public static readonly DependencyProperty ButtonDeleteToolTipProperty =
            DependencyProperty.Register(
                "ButtonDeleteToolTip", typeof(string), typeof(AddDeleteItemControl), new PropertyMetadata("delete"));

        #endregion

        #region Fields

        /// <summary>
        /// a bool to Visibility converter.
        /// </summary>
        private readonly BooleanToVisibilityConverter boolToVisConverter = new BooleanToVisibilityConverter();

        #endregion

        #region Constructors and Destructors

        /// <summary>
        ///   Initializes a new instance of the <see cref="AddDeleteItemControl"/> class. 
        ///   The constructor creates all bindings to the add and delete Buttons.
        /// </summary>
        public AddDeleteItemControl()
        {
            this.InitializeComponent();

            this.AddButton.SetBinding(ButtonBase.CommandProperty, new Binding("ButtonAddCommand") { Source = this });
            this.AddButton.SetBinding(
                RibbonButton.ToolTipTitleProperty, new Binding("ButtonAddToolTip") { Source = this });
            this.AddButton.SetBinding(
                RibbonButton.ToolTipDescriptionProperty, new Binding("ButtonAddToolTipDescription") { Source = this });
            this.AddButton.SetBinding(
                VisibilityProperty, new Binding("AllowAdd") { Source = this, Converter = this.boolToVisConverter });
            this.DeleteButton.SetBinding(
                ButtonBase.CommandProperty, new Binding("ButtonDeleteCommand") { Source = this });
            this.DeleteButton.SetBinding(
                RibbonButton.ToolTipTitleProperty, new Binding("ButtonDeleteToolTip") { Source = this });
            this.DeleteButton.SetBinding(
                RibbonButton.ToolTipDescriptionProperty, new Binding("ButtonDeleteToolTipDescription") { Source = this });
            this.DeleteButton.SetBinding(
                VisibilityProperty, new Binding("AllowDelete") { Source = this, Converter = this.boolToVisConverter });
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///   Allow Execution of the Add Command
        /// </summary>
        public bool AllowAdd
        {
            get
            {
                return (bool)this.GetValue(AllowAddProperty);
            }

            set
            {
                this.SetValue(AllowAddProperty, value);
            }
        }

        /// <summary>
        ///   Allow Execution of the Delete Command
        /// </summary>
        public bool AllowDelete
        {
            get
            {
                return (bool)this.GetValue(AllowDeleteProperty);
            }

            set
            {
                this.SetValue(AllowDeleteProperty, value);
            }
        }

        /// <summary>
        ///   Command Interface for the add command
        /// </summary>
        public ICommand ButtonAddCommand
        {
            get
            {
                return (ICommand)this.GetValue(ButtonAddCommandProperty);
            }

            set
            {
                this.SetValue(ButtonAddCommandProperty, value);
            }
        }

        /// <summary>
        ///   ToolTip, associated to the Add Command Button
        /// </summary>
        public string ButtonAddToolTip
        {
            get
            {
                return (string)this.GetValue(ButtonAddToolTipProperty);
            }

            set
            {
                this.SetValue(ButtonAddToolTipProperty, value);
            }
        }

        /// <summary>
        ///   ToolTip-Description, associated to the Add Command Button
        /// </summary>
        public string ButtonAddToolTipDescription
        {
            get
            {
                return (string)this.GetValue(ButtonAddToolTipDescriptionProperty);
            }

            set
            {
                this.SetValue(ButtonAddToolTipDescriptionProperty, value);
            }
        }

        /// <summary>
        ///   Command Interface for the delete command
        /// </summary>
        public ICommand ButtonDeleteCommand
        {
            get
            {
                return (ICommand)this.GetValue(ButtonDeleteCommandProperty);
            }

            set
            {
                this.SetValue(ButtonDeleteCommandProperty, value);
            }
        }

        /// <summary>
        ///   ToolTip, associated to the Delete Command Button
        /// </summary>
        public string ButtonDeleteToolTip
        {
            get
            {
                return (string)this.GetValue(ButtonDeleteToolTipProperty);
            }

            set
            {
                this.SetValue(ButtonDeleteToolTipProperty, value);
            }
        }

        /// <summary>
        ///   ToolTip-Description, associated to the Delete Command Button
        /// </summary>
        public string ButtonDeleteToolTipDescription
        {
            get
            {
                return (string)this.GetValue(ButtonDeleteToolTipDescriptionProperty);
            }

            set
            {
                this.SetValue(ButtonDeleteToolTipDescriptionProperty, value);
            }
        }

        #endregion
    }
}